package cn.blu10ph.tools.web_ctrl;

public class CmdCtrl {
    protected boolean is_concented = false;
    protected final KeyMsgSend keyMsgSend;
    private String password;
    public CmdCtrl(String password){
        keyMsgSend = new KeyMsgSend();
        this.password = password;
    }

    public boolean cmd(String msg){
        boolean need_close = false;
        String data = "";
        String[] msg_array = msg.split(":");
        if(msg_array.length>1){
            msg = msg_array[0];
            data = msg_array[1];
        }

        System.out.println("msg:"+msg);
        System.out.println("data:"+data);

        if(!is_concented&&(!"password".equals(msg))){
            need_close = true;
            return need_close;
        }
        switch (msg){
            case "heart":
                System.out.println("heart");
                break;
            case "enter":
                keyMsgSend.enter();
                break;
            case "page_up":
                keyMsgSend.page_up();
                break;
            case "page_down":
                keyMsgSend.page_down();
                break;
            case "password":
                if(!this.password.equals(data)){
                    System.out.println("password:no");
                    need_close = true;
                }else{
                    System.out.println("password:ok");
                    is_concented = true;
                }
                break;
            case "close":
                need_close = true;
                is_concented = false;
                break;
            default:
                System.out.println("unknow_cmd:"+msg);
        }
        return need_close;
    }
}
